//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import RefundrulesBox from "../../views/mall/RefundrulesBox.vue";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: RefundrulesBox,
    gridFooter: "",
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: "md-add",
        value: "XJ",
        class: "",
        type: "error",
        index: 1, //显示的位置
        onClick: function () {
          this.$refs.gridBody.model = true;
          this.$refs.gridBody.title = 0;
          this.$nextTick(() => {
            this.$refs.gridBody.ruleForm.refundName = "";
            this.$refs.gridBody.gz_list_tp_index = 0;
            this.$refs.gridBody.gz_list_sj_index = 0;
            this.$refs.gridBody.gz_list_num_index = 0;
            this.$refs.gridBody.gz_list_tpsxf_index = 0;
            this.$refs.gridBody.gz_list_sxffs_index = 0;
            this.$refs.gridBody.gz_list_gq_index = 0;
            this.$refs.gridBody.isApprove = 0;
            this.$refs.gridBody.voluntarilyRefundHour = null;
            this.$refs.gridBody.refundDay = 0;
            this.$refs.gridBody.refundHours = "23:59";
            this.$refs.gridBody.InitialOrder = 0;
            this.$refs.gridBody.checkboxLessthan = false;
            this.$refs.gridBody.Lessthan = 0;
            this.$refs.gridBody.fixedamount.amount = 0;
            this.$refs.gridBody.fixedamount.unit = "0";
            this.$refs.gridBody.formList = [];
            this.$refs.gridBody.stepamount.dayaround = "front";
            this.$refs.gridBody.stepamount.day = 0;
            this.$refs.gridBody.stepamount.time = "23:59";
            this.$refs.gridBody.serviceShargeDiscount = 0;
            this.$refs.gridBody.isAutoEnd = false;
            this.$refs.gridBody.gz_list_sxf_status = false;
            this.$refs.gridBody.autoEnd1 = 0;
            this.$refs.gridBody.autoEnd2 = 0;
          });
        }
      },
      {
        name: "编辑",
        icon: "md-create",
        value: "BJ",
        class: "",
        type: "success",
        index: 2, //显示的位置
        onClick: function () {
          this.$refs.gridBody.title = 1;
          this.$nextTick(() => {
            if (
              this.getSelectRows().length > 1 ||
              this.getSelectRows().length == 0 ||
              this.getSelectRows() == undefined
            ) {
              this.$Message.error("只能选中一行进行编辑");
              return false;
            } else {
              this.$refs.gridBody.model = true;
              let v = this.getSelectRows()[0];
              this.$refs.gridBody.GZID = v.id;
              this.$refs.gridBody.ruleForm.refundName = v.refundName;
              this.$refs.gridBody.gz_list_tp_index = v.basic;
              this.$refs.gridBody.isApprove = v.isApprove;
              console.log(v, "hdasidhdssadjsao")
              this.$refs.gridBody.voluntarilyRefundHour = v.voluntarilyRefundHour;
              this.$refs.gridBody.gz_list_tp_cl(v.basic);
              this.$refs.gridBody.gz_list_sj_index =
                v.afterDate == null ? 0 : 1;
              this.$refs.gridBody.refundDay =
                v.afterDate == null ? v.beforeDate : v.afterDate;
              let ol = v.afterDate == null ? 0 : 1;
              this.$refs.gridBody.gz_list_sj_cl(ol);
              this.$refs.gridBody.refundHours = v.refundHours;
              if (v.refundCount == null) {
                this.$refs.gridBody.gz_list_num_index = 0;
              } else {
                this.$refs.gridBody.gz_list_num_index = 1;
                let o = JSON.parse(v.refundCount);
                this.$refs.gridBody.InitialOrder = o.InitialOrder;
                this.$refs.gridBody.checkboxLessthan =
                  o.Lessthan != 0 ? true : false;
                this.$refs.gridBody.Lessthan = o.Lessthan;
              }
              this.$refs.gridBody.gz_list_tpsxf_index = v.isServiceCharge;
              this.$refs.gridBody.gz_list_sxf_status =
                v.isServiceCharge == 0 ? false : true;
              if (v.fixedamount == null) {
                this.$refs.gridBody.gz_list_sxffs_index = 1;
                let o = JSON.parse(v.stepamount);
                this.$refs.gridBody.stepamount.dayaround = o[0].dayaround;
                this.$refs.gridBody.stepamount.day = o[0].day;
                this.$refs.gridBody.stepamount.time = o[0].time;
                this.$refs.gridBody.fixedamount.amount = o[0].amount;
                this.$refs.gridBody.fixedamount.unit = o[0].unit;
                if (o.length > 1) {
                  let z = o.slice(1);
                  let qh = z[0].dayaround == "front" ? "前" : "后";
                  z[0].jzDay = o[0].day;
                  z[0].day = o[1].day;
                  z[0].dayTimeText =
                    "截止游玩结束日期" +
                    qh +
                    z[0].jzDay +
                    "天的" +
                    (o[0].time != undefined ? o[0].time : "");
                  z.forEach((i, ii, arr) => {
                    let qh = i.dayaround == "front" ? "前" : "后";
                    if (ii > 0) {
                      arr[ii].jzDay = arr[ii - 1].day;
                      arr[ii].dayTimeText =
                        "截止游玩结束日期" +
                        qh +
                        arr[ii].jzDay +
                        "天的" +
                        (i.time != undefined ? i.time : "");
                    }
                  });
                  this.$refs.gridBody.formList = z;
                } else {
                  this.$refs.gridBody.formList = [];
                }
              } else {
                this.$refs.gridBody.gz_list_sxffs_index = 0;
                let o = JSON.parse(v.fixedamount);
                this.$refs.gridBody.fixedamount.amount = o.amount;
                this.$refs.gridBody.fixedamount.unit = o.unit.toString();
              }
            }

            // console.log(v, "v");
            // if (v == undefined) {
            //   this.$refs.gridBody.model = false;
            //   this.$Message.error("只能选中一行进行编辑");
            //   return false;
            // } else {
            //   this.$refs.gridBody.model = true;
            // }

            // this.$refs.gridBody.gz_list_gq_index = v.isExpirationRefundable
            // if (v.isExpirationRefundable == 1) {
            //   this.$refs.gridBody.autoEnd1 = v.autoEnd;
            //   this.$refs.gridBody.autoEnd2 = 0
            // } else if (v.isExpirationRefundable == 2) {
            //   this.$refs.gridBody.autoEnd1 = 0
            //   this.$refs.gridBody.autoEnd2 = v.autoEnd;
            // }
            // this.$refs.gridBody.serviceShargeDiscount = v.serviceShargeDiscount == null ? 0 : v.serviceShargeDiscount;
            // this.$refs.gridBody.isAutoEnd = v.isAutoEnd == null ? false : true
          });
        }
      }
    ],
    box: [],
    detail: []
  }, //扩展的按钮
  methods: {
    //事件扩展

    onInit () {
      this.$store.getters.data().viewPageTest = this;
    },
    rowClick ({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);

      return true;
    },
    delBeforeDataAsync (ids, rows) {
      let refundrulesid = rows.map(i => i.refundCode);
      let obj = {
        url: "/api/distriProducts/getPageData",
        params: {
          order: "desc",
          page: 1,
          rows: 30,
          sort: "createDate",
          wheres: `[{\"name\":\"refundrulesid\",\"value\":\"${refundrulesid.join()}\",\"displayType\":\"checkbox\"}]`
        }
      };
      return obj;
    }
  }
};
export default extension;
